home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d939.lha / ExtraCmds / source_etc.lha / src / Copyright.c < prev    next >
C/C++ Source or Header  |  1993-10-22  |  4KB  |  177 lines

  1. /*   ---------------------------------      -------     
  2.  *   |\  | | | | |  |.| |   \|  |/ /|\      |||||||     
  3.  *   | | | |/  | |\ |/  |/|  |\ |/  |    ?  ---+---  =< 
  4.  *   | | | |   | |  |     |  |  |   |     \qqqqqqqqq/   
  5.  *   ---------------------------------  ~~~~~~~~~~~~~~~~
  6.  *  COPYRIGHT - Prints embedded copyright messages
  7.  *  Copyright (C) 1993 Torsten Poulin
  8.  *
  9.  *  This program is free software; you can redistribute it and/or modify
  10.  *  it under the terms of the GNU General Public License as published by
  11.  *  the Free Software Foundation; either version 2 of the License, or
  12.  *  (at your option) any later version.
  13.  *
  14.  *  This program is distributed in the hope that it will be useful,
  15.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *  GNU General Public License for more details.
  18.  *
  19.  *  You should have received a copy of the GNU General Public License
  20.  *  along with this program; if not, write to the Free Software
  21.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  *
  23.  *  The author can be contacted by s-mail at
  24.  *    Torsten Poulin
  25.  *    Banebrinken 99, 2, 77
  26.  *    DK-2400 Copenhagen NV
  27.  *    DENMARK
  28.  *
  29.  * $Id: Copyright.c,v 37.3 93/03/01 12:51:16 Torsten Rel $
  30.  * $Log:    Copyright.c,v $
  31.  * Revision 37.3  93/03/01  12:51:16  Torsten
  32.  * Changed all occurrences of "struct DosBase *" to "struct DosLibrary *"
  33.  * 
  34.  * Revision 37.2  93/02/24  19:00:33  Torsten
  35.  * Restructured the code.
  36.  * Template is now FILE/M/A.
  37.  * Understands patterns.
  38.  * Prints a header before each message.
  39.  * 
  40.  * Revision 37.1  93/02/07  11:43:43  Torsten
  41.  * This is the initial revision.
  42.  * 
  43.  */
  44.  
  45. #include <exec/types.h>
  46. #include <exec/memory.h>
  47. #include <dos/dos.h>
  48. #include <dos/dostags.h>
  49. #include <clib/dos_protos.h>
  50. #include <clib/exec_protos.h>
  51. #ifdef __SASC
  52. #include <pragmas/dos_pragmas.h>
  53. #include <pragmas/exec_pragmas.h>
  54. #endif
  55. #include "tastlib.h"
  56. #include "copyright_rev.h"
  57.  
  58. #define PROGNAME "Copyright"
  59. #define TEMPLATE "FILE/M/A"
  60. #define OPT_FILE 0
  61.  
  62. char const versionID[] = VERSTAG;
  63. char const copyright[] = "$COPYRIGHT:Copyright © 1993 Torsten Poulin$";
  64.  
  65. typedef struct {
  66.   struct DosLibrary *DOSBase;
  67. } Global;
  68.  
  69. BOOL match(BPTR fp, char *s, Global *global);
  70. LONG scan(UBYTE *filename, Global *global);
  71.  
  72. LONG entrypoint(VOID)
  73. {
  74.   struct DosLibrary *DOSBase;
  75.   struct RDArgs     *args;
  76.   Global            *global;
  77.   LONG arg[1];
  78.   LONG rc = RETURN_OK;
  79.  
  80.   if (!(DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37L)))
  81.     return RETURN_FAIL;
  82.  
  83.   if (!(global = AllocVec(sizeof(Global), MEMF_PUBLIC | MEMF_CLEAR)))
  84.   {
  85.     PrintFault(ERROR_NO_FREE_STORE, PROGNAME);
  86.     rc = RETURN_FAIL;
  87.   }
  88.   else
  89.   {
  90.     global->DOSBase = DOSBase;
  91.  
  92.     arg[OPT_FILE] = 0L;
  93.  
  94.     if (!(args = ReadArgs(TEMPLATE, arg, NULL)))
  95.     {
  96.       printerror(PROGNAME, global);
  97.       rc = RETURN_ERROR;
  98.     }
  99.     else
  100.     {
  101.       rc = foreach((UBYTE **) arg[OPT_FILE], scan, global);
  102.       FreeArgs(args);
  103.  
  104.       if (rc == ERROR_BREAK)
  105.       {
  106.     PrintFault(ERROR_BREAK, NULL);
  107.     rc = RETURN_WARN;
  108.       }
  109.       else if (rc == ERROR_NO_FREE_STORE)
  110.       {
  111.     PrintFault(ERROR_NO_FREE_STORE, PROGNAME);
  112.     rc = RETURN_FAIL;
  113.       }
  114.       else if (rc != RETURN_OK)
  115.     printerror(PROGNAME, global);
  116.     }
  117.     FreeVec(global);
  118.   }
  119.   CloseLibrary((struct Library *) DOSBase);
  120.   return rc;
  121. }
  122.  
  123.  
  124. BOOL match(BPTR fp, char *s, Global *global)
  125. {
  126.   struct DosLibrary *DOSBase = global->DOSBase;
  127.   LONG c;
  128.  
  129.   while (*s == (c = FGetC(fp)) && c != EOF)
  130.   {
  131.     s++;
  132.     if (!*s)
  133.       return TRUE;
  134.   }
  135.   if (c != EOF)
  136.     UnGetC(fp, c);
  137.   return FALSE;
  138. }
  139.  
  140.  
  141. LONG scan(UBYTE *filename, Global *global)
  142. {
  143.   struct DosLibrary *DOSBase = global->DOSBase;
  144.   LONG c;
  145.   BPTR fp;
  146.   BPTR out = Output();
  147.   LONG rc = RETURN_OK;
  148.  
  149.   if (!(fp = Open(filename, MODE_OLDFILE)))
  150.   {
  151.     printerror(PROGNAME, global);
  152.     rc = RETURN_ERROR;
  153.   }
  154.   else
  155.   {
  156.     while ((c = FGetC(fp)) != EOF)
  157.     {
  158.       if (c == '$')
  159.     if(match(fp, "COPYRIGHT:", global))
  160.     {
  161.       PutStr(filename);
  162.       PutStr(" contains the following message:\n");
  163.       /* skip leading blanks */
  164.       while ((c = FGetC(fp)) != EOF && c == ' ')
  165.         ;
  166.       UnGetC(fp, c);
  167.       while ((c = FGetC(fp)) != EOF && c != '\0' && c != '$')
  168.         FPutC(out, c);
  169.       FPutC(out, '\n');
  170.       break;
  171.     }
  172.     }
  173.     Close(fp);
  174.   }
  175.   return rc;
  176. }
  177.